// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2023 HUAWEI TECHNOLOGIES CO., LTD.
 */
#include <linux/mmiotrace.h>
#include <linux/vmalloc.h>
#include <asm/io.h>
#include <asm/memtype.h>

void __iomem *ioremap_to_vaddr(unsigned long vaddr, resource_size_t phys_addr,
				unsigned long size)
{
	return __ioremap_to_vaddr(phys_addr, size, _PAGE_CACHE_MODE_WB,
				  __builtin_return_address(0), false, vaddr);
}
EXPORT_SYMBOL(ioremap_to_vaddr);

void iounmap_from_vaddr(volatile void __iomem *vaddr, resource_size_t phys_addr,
				unsigned long size)
{
	if ((unsigned long)vaddr < VPMEM_BASE_START ||
	    (unsigned long)vaddr >= VPMEM_BASE_END)
		return;

	mmiotrace_iounmap(vaddr);

	memtype_free(phys_addr, phys_addr + size);
	unmap_kernel_range((unsigned long)vaddr, size);
}
EXPORT_SYMBOL(iounmap_from_vaddr);
